'use strict'
import * as echarts from 'echarts'
export function Grid (x = 40, y = 10, x2 = 15, y2 = 30) {
  return { x: x, y: y, x2: x2, y2: y2 }
}

/**
 * 图例
 * @param show
 */
export function Legend (show = true) {
  return {
    orient: 'horizontal',
    x: 'right',
    y: '0',
    top: '0',
    color: '#FFF',
    //  circle，rect ，roundRect，triangle，diamond，pin，arrow，none
    icon: 'rect',
    itemWidth: 10,
    itemHeight: 8,
    itemGap: 15,
    show: show,
    formatter: (name) => {
      return name
    },
    textStyle: {
      color: '#FFF',
      fontSize: 10
    }
  }
}
/**
 * X 轴
 * @param data { Array } ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
 * @param boundaryGap { Boolean } [true] 柱子是否和坐标轴有边框间隔
 */
export function XAxis (data = [], boundaryGap = true) {
  return {
    type: 'category',
    data: data,
    axisLine: {
      show: false,
      lineStyle: {
        color: 'white'
      }
    },
    offset: 2,
    axisTick: {
      show: false,
      alignWithLabel: true,
      lineStyle: {
        color: '#FFF'
      }
    },
    boundaryGap: boundaryGap,
    splitLine: {
      show: false,
      lineStyle: {
        color: ['#243753'],
        type: 'solid'
      }
    },
    axisLabel: {
      show: true,
      fontSize: 10,
      color: '#7BCAFF'
    }
  }
}

/**
 * Y 轴
 * @param config { Object }
 */
export function YAxis (unit = null) {
  return {
    minInterval: 1,
    type: 'value',
    name: unit,
    nameTextStyle: {
      color: '#C1C1C1',
      fontSize: 8,
      nameLocation: 'end',
      padding: [1, 25, 0, 0]
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#243753'
      }
    },
    splitLine: {
      show: true,
      lineStyle: {
        color: ['#243753'],
        type: 'dashed'
      }
    },
    axisTick: {
      show: false
    },
    axisLabel: {
      show: true,
      fontSize: 10,
      color: '#FFF'
    },
    boundaryGap: ['20%', '20%']
  }
}

export function Tooltip (unit = null) {
  return {
    trigger: 'axis',
    axisPointer: {
      type: 'shadow'
    }
  }
}

/**
 * 数据部分
 * @param series { Array } [ 10, 20, 30, 40, 50, 60, 70]
 */
export function Series (data = [], colors = ['0,255,238', '0,153,255', '125,255,201', '255,236,179', '119,253,255', '125,255,201', '255,236,179', '119,253,255']) {
  return [
    {
      type: 'bar',
      barWidth: '16',
      color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
        {
          offset: 0,
          color: 'rgba(' + colors[0] + ',1)'
        },
        {
          offset: 1,
          color: 'rgba(' + colors[1] + ',0)'
        }
      ]),
      data: data,
      showBackground: true,
      backgroundStyle: {
        color: 'rgba(0,37,126,0.94)'
      }
    }
  ]
}
